//
//  SCRNEventManager.m
//  Shuaiche
//
//  Created by xiangtao on 2024/2/20.
//  Copyright © 2024 ShuaiChe. All rights reserved.
//

#import "SCRNEventManager.h"

#define COMMONEVENT @"commonEvent"
#define PAYSUCCESS @"paySuccess"
#define UPLOADSUCCESS @"uploadSuccess"
#define UPLOADIMSUCCESS @"uploadIMSuccess"
#define UPLOADCANCEL @"uploadCancel"
#define LOGINSUCCESS @"loginSuccess"
#define SELECT_CAR_RESULT_LISTENER @"selectCarResultListener"
#define PLAYAUDIOFINISH @"playAudioFinish"
#define UPLOADAUDIOFINISH @"uploadAudioFinish"
#define UPLOADAUDIOFAILED @"uploadAudioFailed"
#define OUTSIDEWEBJUMP @"outsideWebJump"
#define FOURSQUERY @"foursQuery"




@implementation SCRNEventManager
static SCRNEventManager *instance = nil;

RCT_EXPORT_MODULE();

+ (instancetype)shareInstance {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    instance = [[self alloc] init];
  });
  return instance;
}

- (NSArray<NSString *> *)supportedEvents
{
  return @[COMMONEVENT,PAYSUCCESS,UPLOADSUCCESS,UPLOADIMSUCCESS,UPLOADCANCEL,LOGINSUCCESS,SELECT_CAR_RESULT_LISTENER,PLAYAUDIOFINISH,UPLOADAUDIOFINISH,UPLOADAUDIOFAILED,OUTSIDEWEBJUMP];
}

//通用Event
RCT_EXPORT_METHOD(commonEvent:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[COMMONEVENT, parameters]
                  completion:NULL];
}

//支付成功
RCT_EXPORT_METHOD(paySuccess) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[PAYSUCCESS]
                  completion:NULL];
}

RCT_EXPORT_METHOD(uploadSuccess:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[UPLOADSUCCESS, parameters]
                  completion:NULL];
}

RCT_EXPORT_METHOD(uploadIMSuccess:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[UPLOADIMSUCCESS, parameters]
                  completion:NULL];
}

RCT_EXPORT_METHOD(uploadCancel) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[UPLOADCANCEL]
                  completion:NULL];
}

RCT_EXPORT_METHOD(loginSuccess:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[LOGINSUCCESS, parameters]
                  completion:NULL];
}

RCT_EXPORT_METHOD(selectCarResultListener:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[SELECT_CAR_RESULT_LISTENER, parameters]
                  completion:NULL];
}

//支付成功
RCT_EXPORT_METHOD(playAudioFinish) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[PLAYAUDIOFINISH]
                  completion:NULL];
}

//上传语音成功
RCT_EXPORT_METHOD(uploadAudioFinish:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[UPLOADAUDIOFINISH, parameters]
                  completion:NULL];
}

//音频上传失败
RCT_EXPORT_METHOD(uploadAudioFailed:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[UPLOADAUDIOFAILED, parameters]
                  completion:NULL];
}

RCT_EXPORT_METHOD(outsideWebJump:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[OUTSIDEWEBJUMP,parameters]
                  completion:NULL];
}

RCT_EXPORT_METHOD(foursQuery:(NSDictionary *)parameters) {
  [self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
                      method:@"emit"
                        args:@[FOURSQUERY,parameters]
                  completion:NULL];
}

@end
